package com.zhukaoguan.boot11.controller;

import com.zhukaoguan.boot11.entity.News;
import com.zhukaoguan.boot11.mapper.NewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/news/")
public class NewsController {
    @Autowired(required = false)
    NewsMapper mapper;
    @RequestMapping("search")
    public List<News> search(String kw){
        return mapper.selectLike(kw);
    }
    @RequestMapping("select")
    public List<News> select(){
        System.out.println(mapper.select());
        return mapper.select();
    }
    @RequestMapping("delete")
    public void delete(int id){
        mapper.delete(id);
    }
    @RequestMapping("insert")
    public int insert(News news){
        news.setCreated(Date.from(Instant.now()));
        return mapper.insert(news);
    }
    @RequestMapping("selectLimit")
    public List<News> limit(){
        return mapper.limit();
    }
    @RequestMapping("selectByLike")
    public List<News> byLike(String kw){
        System.out.println(mapper.byLike(kw));
        return mapper.byLike(kw);
    }

}
